<template>
  <div>
    <!-- <h1>地址管理</h1> -->
    <van-address-list
      v-model="chosenAddressId"
      :list="list"
      default-tag-text="默认"
      @add="onAdd"
      @edit="onEdit"
      @select="select($event)"
    />
  </div>
</template>

<script>
import axios from "axios";

export default {
  data() {
    return {
      chosenAddressId: "1",
      list: [],

    };
  },
  methods: {
    onAdd() {
      this.$router.push("/addressAdd");
    },
    onEdit(e) {
      this.$router.push("/addressAdd?id=" + e.id);
    },
    select(e){
      this.$router.replace("/orders?addressId="+e.id)
    }
  },
  activated() {
    axios({
      url: "/api/addresslist",
      method: "get",
      params: {
        uid: JSON.parse(localStorage.getItem("userInfo")).uid,
      },
    }).then((res) => {
      console.log(res);
      this.list=[];
      if(res.data.list == null){
        return;
      }
      res.data.list.forEach((item, index) => {
        this.list.push({
          id: item.id,
          name: item.username,
          tel: item.userphone,
          address: item.useraddress,
          isDefault: item.status?true:false,
        });
      });
    });
  },
};
</script>

<style>
</style>